<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登录</title>
    <link href="${pageContext.request.contextPath }/csslib/login.css" rel="stylesheet">
</head>
<body>
  <jsp:include page="/front/common/navbar.jsp"></jsp:include>
  <div class="header">
      <div class="header-top clearfix">
         <div class="header-left">
             <div class="logo"><a href="${pageContext.request.contextPath }/front/index.jsp"><img src="${pageContext.request.contextPath }/images/logo.jpg"></a></div>
             <div class="header-site">
                 <h2>账号登录</h2>
             </div>
         </div>
       </div>
  </div>
   <div class="login-wrap">
      <div class="login-box">
          <div class="lb-left">
              <form method="post" id="login-form">
              <div class="form">
                  <p class="lf-top"><span class="error-tip"></span></p>
                  <dl>
                      <dt>用户名：</dt>
                      <dd>
                      <input type="text" class="login-text" name="code" />
                      <span class="error-tip" style="display:none">请输入用户名</span>
                      </dd>
                  </dl>
                  <dl>
                      <dt>密码：</dt>
                      <dd>
                      <input type="password" class="login-text" name="password" />
                      <span class="error-tip" style="display:none">请输入密码</span>
                      </dd>
                  </dl>
                  <dl>
                      <dt>验证码：</dt>
                      <dd class="checkCode">
                          <input type="text" class="login-text yzm-text" name="randomCode"  />
                          <img src="" id="code-img">
                          看不清楚？<a href="javascript:;" class="color-blue">换一张</a>
                          <p class="error-tip"  style="display:none">请输入验证码</p>
                      </dd>
                       
                  </dl>
                  <dl class="form-bt">
                      <dd>
                          <label><input type="checkbox" class="input-middle" />&nbsp;两周内自动登录</label>
                      </dd>
                  </dl>
                  <dl class="form-bt">
                      <dd>
                          <input type="button" class="login-button" id="login-button" value="登录">
                          <a href="#" class="color-333">忘记密码?</a>
                      </dd>
                  </dl>
                  <dl class="form-bt">
                      <dd class="other-tip">使用合作账户登录</dd>
                      <dd  class="login-other">
                          <a href="#" class="login-qq"></a>
                          <a href="#" class="login-weibo"></a>
                          <a href="#" class="login-taobao"></a>
                      </dd>
                  </dl>
              </div>
              </form>
          </div>
          <div class="lb-right">
              <div class="login-side">
                  <h3>注册</h3>
                  <p class="ls-no">还木有账号？</p>
                  <p><input type="button" class="button-side" value="免费注册" /></p>
              </div>
          </div>
      </div>
  </div>
  <jsp:include page="/front/common/footer.jsp"></jsp:include>
  <script src="${pageContext.request.contextPath }/jslib/jquery-1.8.3.min.js"></script>
  <script  src="${pageContext.request.contextPath }/jslib/common.js"></script>
  <script type="text/javascript">
  
    document.getElementById("code-img").src = "${pageContext.request.contextPath }/yyj/valid.action";
  
  
    $(".form input").focus(function(){
    	
    	$(this).parent().find(".error-tip").hide();
    });
    $("#login-button").click(function(){
    	var $code = $("input[name='code']")
    	var $password = $("input[name='password']");
    	var $randomCode = $("input[name='randomCode']");
    	if($.trim($code.val()) === ""){
    		$code.next().show();
    		return;
    	}
    	if($.trim($password.val()) === ""){
    		$password.next().show();
    		return;
    	}
    	if($.trim($randomCode.val()) === ""){
    		$randomCode.parent().find(".error-tip").show();
    		return;
    	}
    	
    	 //ajax登录
    	var actionURL = "consumer.action?command=login";
 		var params = $("#login-form").serialize();
 			
 		jQuery.ajax({
 			url: actionURL,
 			type: "post",
 			cache: false,
 			data: params,
 			success: function(result){
 				if("-1" === result){
 					$(".lf-top span").text("验证码错误");
 				}else if("-2" === result){
 					$(".lf-top span").text("用户名或者密码错误");
 				}else{
 					 window.location.href = '/yyj/front/index.jsp';
 					//跳转页面
 				}
 			}
 		});
 		
    });
  
  </script>
</body>
</html>